package com.example.demo.controller;

import com.example.demo.domain.entity.ChapterEntity;
import com.example.demo.service.ChapterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping(value = "/chapter")
public class ChapterController {

	@Autowired
	private ChapterService chapter;

	@GetMapping("/get")
	public ResponseEntity<ChapterEntity> getCapterInfo (
			@RequestParam Integer id)throws Exception{
		ChapterEntity entity = chapter.selectChapter(id);
		log.info("data: {}", entity);
		return ResponseEntity.ok(entity);
	}

	//更新内容
	@PutMapping("/insert")
	public void insertCapter(@RequestBody ChapterEntity entity){

		chapter.insertCapter(entity.getBookId(), entity.getContent());

	}

}
